package com.tencent.sr.iris.activity.service.event.handler;

import com.tencent.sr.iris.activity.domain.event.dto.ActivityDTO;
import com.tencent.sr.iris.activity.domain.event.dto.ActivityTaskDTO;
import com.tencent.sr.iris.activity.interfaces.event.dto.ActivityEventDTO;
import com.tencent.sr.iris.activity.service.activity.IrisActivityService;
import com.tencent.sr.iris.activity.service.event.activity.IrisActivityExecutor;
import java.util.List;
import java.util.Objects;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Lists;
import org.springframework.stereotype.Component;

/**
 * 佣金变更事件处理器
 *
 * 注：事件处理器的spring对象名使用对应事件枚举的code
 * com.tencent.sr.iris.activity.interfaces.enums.ActivityEventTypeEnum
 *
 * @author xiaojun
 */
@Slf4j
@Component("DISTRIBUTION_ORDER")
public class IrisDistributionOrderEventHandler extends AbstractIrisEventHandler {

    @Resource
    private IrisActivityService activityService;

    @Override
    public void after(ActivityEventDTO eventDTO) {

    }

    @Override
    void process(ActivityEventDTO eventDTO, List<String> eventHandingInfoList) {
        //补充事件pid
        addParameterForEvent(eventDTO);
        //查询佣金变更事件对应的活动
        ActivityDTO activity = getActivity();
        IrisActivityExecutor activityExecutor = getActivityExecutor(eventDTO, activity);
        activityExecutor.execute(eventDTO, activity);
        eventHandingInfoList
                .add(this.getClass().getSimpleName() + "处理成功,idempotent:" + eventDTO.getIdempotent());
    }

    @Override
    List<ActivityTaskDTO> getRelatedTaskList(String eventType) {
        return null;
    }

    @Override
    void baseDataProcess(ActivityEventDTO eventDTO) {

    }

    protected ActivityDTO getActivity() {
        //查询邀请有礼活动
        ActivityDTO inviteActivity = activityService.getActivityAllTask(activityConfig.getInviteGiftActivityId());
        if (Objects.isNull(inviteActivity)) {
            log.error("未查询到邀请有礼活动信息,activityBizId={}", activityConfig.getInviteGiftActivityId());
        }
        return inviteActivity;
    }
}
